import Router from 'koa-router'
import jwk from 'jsonwebtoken'
import { jwtConfig } from "../config/index";

const route = new Router({
    prefix: '/api' // 统一前缀，接口全部为 /api/xxx 格式
})

route.get('/', async (ctx, next) => {
    ctx.body = 'hello koa2'
})
    .get('/login', async (ctx, next) => {
        let userToken = {
            name: 'nicchan'
        }
        jwk.sign(userToken, jwtConfig.secret, { expiresIn: '3h' })
        ctx.body = {
            token
        }
    })
    .get('/jwt', verify, async (ctx, next) => {
        ctx.body = 'token available'
    })

export default route